﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LevelEditor
{
    public class SceneObject : Entity
    {
        public SceneObject(string typename, string filename)
            : base(typename)
        {
            mesh = new Mesh(filename);
        }

        public override void Draw()
        {
            graphics.effect = EffectManager.BasicShader;
            graphics.effect.Parameters["World"].SetValue(mesh.World);
            graphics.effect.Parameters["Projection"].SetValue(Camera.instance.Projection);
            graphics.effect.Parameters["View"].SetValue(Camera.instance.View);
            graphics.effect.CurrentTechnique.Passes[0].Apply();
            
            mesh.Draw(graphics.device);
            if (selected)
            {
                Effect e = EffectManager.FlatShader;
                Camera.instance.FormatEffect(e);
                e.Parameters["World"].SetValue(mesh.World);
                e.Parameters["color"].SetValue(Color.White.ToVector4());
                e.CurrentTechnique.Passes[0].Apply();
                mesh.Draw(graphics.device, PrimitiveType.LineList);
            }
            graphics.effect = null;

            base.Draw();
        }
    }
}